package com.lmc.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lmc.R;
import com.lmc.entity.RecreationList;
import com.lmc.recreation.RecreationActivity;
import com.lmc.util.GlideUtil;

import java.util.List;

public class CrosstalkListAdapter extends RecyclerView.Adapter<CrosstalkListAdapter.ViewHolder> {
    Context context;
    List<RecreationList.DataBean.ItemsBean> list;

    public CrosstalkListAdapter(Context context, List<RecreationList.DataBean.ItemsBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public CrosstalkListAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.lmc_crosstalk_list_item, parent, false));
    }

    @Override
    public void onBindViewHolder(CrosstalkListAdapter.ViewHolder holder, int position) {

        final RecreationList.DataBean.ItemsBean bean = list.get(position);
        GlideUtil.setImg(context,holder.thumbnail,bean.getImage());
        holder.text.setText(bean.getName());

        holder.layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, RecreationActivity.class);
                intent.putExtra("id",bean.getId());
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView thumbnail;
        TextView text;
        View layout;
        public ViewHolder(View itemView) {
            super(itemView);
            thumbnail = itemView.findViewById(R.id.thumbnail);
            text = itemView.findViewById(R.id.text);
            layout = itemView.findViewById(R.id.layout);
        }
    }

}
